package operation;

import book.BookList;

import java.util.Scanner;

public class ReturnOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("归还图书!");
        System.out.print("请输入想要归还的图书:");
        Scanner scanner=new Scanner(System.in);
        String name=scanner.nextLine();
        int curSize=bookList.getUsedSize();
        for (int i=0; i < curSize; i++) {
            if(bookList.getBook(i).getName().equals(name)) {
                if(!bookList.getBook(i).isBorrowed()) {
                    System.out.println("不需要归还该图书!");
                    return;
                }
                bookList.getBook(i).setBorrowed(false);
                System.out.println("成功归还图书!");
                return;
            }
        }
        System.out.println("你没有借阅过这本书无需归还!");
    }
}
